package com.hh.dao;

import com.alibaba.fastjson.JSONObject;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class PingGuTotalDao {
    public final static String cfn = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

    public final static String url = "jdbc:sqlserver://212.129.155.194:1433;DatabaseName=JCYY";
    public final static String user = "sa";
    public final static String password = "ZJzhengg@163.com";
    public JSONObject getPingGutToTal() {
        Connection con = null;
        PreparedStatement statement = null;
        ResultSet res = null;
        JSONObject o = new JSONObject();

        try {
            Class.forName(cfn);
            con = DriverManager.getConnection(url, user, password);
            String sql = "SELECT * FROM PD_RYPDB1 where TJBZ=1;";
            System.out.println(sql);
            statement = con.prepareStatement(sql);
            res = statement.executeQuery();
            int count = 0;
            while (res.next()) {
                count++;
            }

            int totalSize = count / 6;
            int moSize = count % 6;
            if (moSize > 0) {
                o.put("totalSize", totalSize + 1);
            } else {
                o.put("totalSize", totalSize);
            }
            System.out.println("条数:        " + count);
            System.out.println("页数：       "+totalSize);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        } finally {
            try {
                if (res != null) res.close();
                if (statement != null) statement.close();
                if (con != null) con.close();
            } catch (Exception e2) {
                // TODO: handle exception
                e2.printStackTrace();
            }
        }

        return o;
    }

}
